from django.db import models

# Create your models here.

class TargetType(models.Model):
    """  爬取目标类型:
    1. Twitter
    2. Facebook
    3. Slack
    4. Reddit
    5. Other
    """
    name = models.CharField(max_length=100)
    spider = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True, blank=True)

class Target(models.Model):
    """
    爬取目标。可以上面支持的爬取类型，也可以是官网、交易所网站，等等。对于同一站点的不同页面，算作不同的目标。
    """
    name = models.CharField(max_length=200)
    type = models.ForeignKey(TargetType, on_delete=models.CASCADE)
    spider = models.CharField(max_length=200)
    start_url = models.TextField()
    last_identifer = models.CharField(max_length=200)
    last_crawl_time = models.DateTimeField(auto_now_add=True, blank=True)
    create_time = models.DateTimeField(auto_now_add=True, blank=True)

class Tag(models.Model):
    """
    标签。主要是币种代号、交易所代号等。
    """
    name = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True, blank=True)

class TargetTag(models.Model):
    """
    目标和标签对应关系
    """
    target = models.ForeignKey(Target, on_delete=models.CASCADE)
    tagg = models.ForeignKey(Tag, on_delete=models.CASCADE)

class Crawl(models.Model):
    """
    爬取记录
    """
    target = models.ForeignKey(Target, on_delete=models.CASCADE)
    status = models.IntegerField(default=0)
    create_time = models.DateTimeField(auto_now_add=True, blank=True)

class CrawlResult(models.Model):
    """
    爬取结果
    """
    crawl = models.ForeignKey(Crawl, on_delete=models.CASCADE)
    title = models.TextField()
    link = models.TextField()
    brief = models.TextField()
    create_time = models.DateTimeField(auto_now_add=True, blank=True)
